﻿using Shop.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WxApi.ApiResult;

namespace Shop.Pay
{
    public partial class ResultNotifyPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //支付结果返回界面
            if (Request.HttpMethod == "POST")
            {
                var result = WxPayResultApi.WxPayResult(Request.InputStream);
                //获取微信订单号，商户订单号，并更新至数据库表
                if (result.return_code == "SUCCESS")
                {
                    string transaction_id = result.transaction_id;//微信支付订单号
                    string out_trade_no = result.out_trade_no;//商户订单号
                    StringBuilder sql = new StringBuilder();
                    sql.Append(string.Format(@"DECLARE @count INT
 SELECT @count=COUNT(1) FROM dbo.[SoPreWxPay] WHERE [cSOCode]='{0}'", out_trade_no));
                    sql.Append(" if(isnull(@count,0)=0) begin ");
                    sql.Append(string.Format(@" INSERT INTO [ShopWPMC].[dbo].[SoPreWxPay]([cSOCode],[WxPayCode],[dDate],[cDate])VALUES('{0}','{1}','{2}',GETDATE())", out_trade_no, transaction_id, DateTime.Now.ToShortDateString()));
                    sql.Append(" end ");
                    HandleSQL.getObj(sql.ToString());
                }
                else
                {

                }
            }
        }
    }
}